home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
TUTORIAL
/
0855.ZIP
/
ASSMAC.MAC
< prev
next >
Wrap
Text File
|
1980-01-01
|
36KB
|
564 lines
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; ASSEMBLE.MAC ;;
;; ;;
;; Sample macro library for the IBM PC Macro Assembler ;;
;; ;;
;; (C) Copyright 1983 ;;
;; by ;;
;; Jerry D. Stuckle ;;
;; ;;
;; Released to Public Domain ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Clear Macro R1,R2,R3,R4,R5,R6,R7,R8
;;***************************************************************************;;
;; ;;
;; Macro: Clear ;;
;; ;;
;; Description: Clear registers ;;
;; ;;
;; Paramaters: Up to 8 registers to be cleared ;;
;; ;;
;; Input: N/A ;;
;; ;;
;; Output: Requested registers set to binary 0's ;;
;; ;;
;; Registers Used: None ;;
;; ;;
;;***************************************************************************;;
Irp Rx,<R1,R2,R3,R4,R5,R6,R7,R8> ;Register list
Ifnb <Rx> ;For each register in list
Xor Rx,Rx ;Clear the register
Endif ;End of Ifidn
Endm ;End of Irp
Endm ;Macro end
Cls Macro
Local Cls1,Clsd
;;***************************************************************************;;
;; ;;
;; Macro: Cls ;;
;; ;;
;; Description: Clear the display screen ;;
;; ;;
;; Paramaters: None ;;
;; ;;
;; Input: None ;;
;; ;;
;; Output: None ;;
;; ;;
;; Registers Used: AX,DX ;;
;; ;;
;;***************************************************************************;;
Display Clsd ;Display the Dos2 String
Jmp Short Cls1 ;Go around the string data
Clsd Db 1bh,'[2J$' ;Data for Dos Call
Cls1 Label Near
Endm
Color Macro Foreground,Background
Local Cold,Col1
;;***************************************************************************;;
;; ;;
;; Macro: Color ;;
;; ;;
;; Description: Sets display color ;;
;; ;;
;; Paramaters: Foreground Color, Background Color ;;
;; ;;
;; Input: None ;;
;; ;;
;; Output: None ;;
;; ;;
;; Registers Used: AX,DX ;;
;; ;;
;;***************************************************************************;;
Display Cold ;Display the color string
Jmp Short Col1 ;Go around the string
Cold Db 1bh,'[' ;Start of string
Ifidn <Foreground>,<Normal> ;If normal request
Db '0' ;Normal Foreground
Else
Ifidn <Foreground>,<Bold> ;If Bold Request
Db '1' ;Bold Foreground
Else
Ifidn <Foreground>,<Underscore> ;If Underscored
Db '4' ;Underscore Foreground
Else
Ifidn <Foreground>,<Blink> ;If Blink request
Db '5' ;Blink Foreground
Else
Ifidn <Foreground>,<Reverse> ;If Reverse request
Db '7' ;Reverse Video
Else
Ifidn <Foreground>,<Invisible> ;If Invisable Request
Db '8' ;Invisable (No-Show)
Else
Ifidn <Foreground>,<Black> ;If Black Request
Db '30' ;Black Foreground
Else
Ifidn <Foreground>,<Red> ;If Red Request
Db '31' ;Red Foreground
Else
Ifidn <Foreground>,<Green> ;If Green Request
Db '32' ;Green Foreground
Else
Ifidn <Foreground>,<Yellow> ;If Yellow Request
Db '33' ;Yellow Foreground
Else
Ifidn <Foreground>,<Blue> ;If Blue Request
Db '34' ;Blue Foreground
Else
Ifidn <Foreground>,<Magenta> ;If Magenta Request
Db '35' ;Magenta Foreground
Else
Ifidn <Foreground>,<Cyan> ;If Cyan Request
Db '36' ;Cyan Foreground
Else
Ifidn <Foreground>,<White> ;If White Request
Db '37' ;White Foreground
Endif
Endif
Endif
Endif
Endif
Endif
Endif
Endif
Endif
Endif
Endif
Endif
Endif
Endif
Ifnb <Foreground> ;If we have foreground...
Ifnb <Background> ;And background colors
Db ';' ;Put in a Seperator
Endif
Endif
Ifidn <Background>,<Black> ;If Black Request
Db '40' ;Black Background
Else
Ifidn <Background>,<Red> ;If Red Request
Db '41' ;Red Background
Else
Ifidn <Background>,<Green> ;If Green Request
Db '42' ;Green Background
Else
Ifidn <Background>,<Yellow> ;If Yellow Request
Db '43' ;Yellow Background
Else
Ifidn <Background>,<Blue> ;If Blue Request
Db '44' ;Blue Background
Else
Ifidn <Background>,<Magenta> ;If Magenta Request
Db '45' ;Magenta Background
Else
Ifidn <Background>,<Cyan> ;If Cyan Request
Db '46' ;Cyan Background
Else
Ifidn <Background>,<White> ;If White Request
Db '47' ;White Background
Endif
Endif
Endif
Endif
Endif
Endif
Endif
Endif
Col1 Label Near ;Skip around data
Endm
Cursor Macro Function,Area
;;***************************************************************************;;
;; ;;
;; Macro: Cursor ;;
;; ;;
;; Description: Save or set current cursor type, blank cursor on screen ;;
;; ;;
;; Paramaters: Function (Save,Set or Erase), Data or Data address ;;
;; ;;
;; Input: Cursor start and end lines (Set only) ;;
;; ;;
;; Output: Cursor start and end lines (Save only) ;;
;; ;;
;; Registers Used: AX,CX (DS used and restored) ;;
;; ;;
;;***************************************************************************;;
Ifidn <Function>,<Erase> ;If cursor erase requested
Mov AH,1 ;Set cursor mode
Mov CX,0F0FH ;Start and end on line 15
Int 10h ;Go do a video interrupt
Else
Ifidn <Function>,<Save> ;If cursor save request
Push DS ;Save DS
Mov AX,40h ;Get segment 40h in AX
Mov DS,AX ;And put it in DS
Mov CX,DS:60h ;Get current cursor mode
Pop DS ;Restore DS
Mov Area,CX ;And move cursor mode to Area
Else
Ifidn <Function>,<Set> ;If cursor set request
Mov CX,Area ;Get cursor mode in CX
Mov AH,1 ;Set cursor mode
Int 10h ;Go do video interrupt
Endif
Endif
Endif
Endm
Cvd Macro Dest,Org
Local Cvbp,Cvde
;;***************************************************************************;;
;; ;;
;; Macro: Cvd ;;
;; ;;
;; Description: Convert binary number to Ascii decimal number ;;
;; ;;
;; Paramaters: Output Label, Input Label ;;
;; ;;
;; Input: Word binary number ;;
;; ;;
;; Output: 4 Byte decimal number ;;
;; ;;
;; Registers Used: AX,BX,DX,DI ;;
;; ;;
;;***************************************************************************;;
Ifdif <Org>,<AX> ;If binary value not in AX
Mov AX,Word ptr Org ;Move origin to AX
Endif
Lea DI,Dest ;Get address of destination
Mov BL,100d ;Divisor to BL
Div BL ;Divide by 100
Mov BH,AH ;Save remainder in BH
Call Cvdp ;Convert highorder to decimal
Mov AL,BH ;Get remainder
Call Cvdp ;Convert low order to decimal
Jmp Short Cvde ;Jump around proc
Cvdp Proc Near
Aam ;Convert to packed decimal
Or AX,3030h ;Convert to Ascii
Mov [DI],AH ;Store high order byte
Inc DI ;Point to next byte
Mov [DI],AL ;Store low order byte
Inc DI ;Point to next byte
Ret ;Return to caller
Cvdp Endp
Cvde Label Near
Endm
Display Macro String
;;***************************************************************************;;
;; ;;
;; Macro: Display ;;
;; ;;
;; Description: Print an ascii string on the screen ;;
;; ;;
;; Paramaters: Label of string to be printed ;;
;; ;;
;; Input: Ascii string, ending with a $ ;;
;; ;;
;; Output: None ;;
;; ;;
;; Registers Used: AX,DX ;;
;; ;;
;;***************************************************************************;;
Lea DX,String ;Address of string to display
Doscall 9 ;Dos Print string function
Endm
Doscall Macro Function
;;***************************************************************************;;
;; ;;
;; Macro: Doscall ;;
;; ;;
;; Description: Set up and execute requested DOS function call ;;
;; ;;
;; Paramaters: Function to be called ;;
;; ;;
;; Input: None ;;
;; ;;
;; Output: None ;;
;; ;;
;; Registers Used: AX ;;
;; ;;
;;***************************************************************************;;
Mov AH,Function ;Get function in AH
Int 21h ;Dos Call
Endm
Getdate Macro Dest,Type
Local Gdte,Gtdp
;;***************************************************************************;;
;; ;;
;; Macro: Getdate ;;
;; ;;
;; Description: Gets current date into destination ;;
;; ;;
;; Paramaters: Destination, Type of date (Char or Bin) ;;
;; ;;
;; Input: None ;;
;; ;;
;; Output: MM/DD/YY (Char) or MDYY (Bin) ;;
;; ;;
;; Registers Used: AX,BX,CX,DX,DI ;;
;; ;;
;;***************************************************************************;;
Ifidn <Type>,<Char> ;If character request
Doscall 2Ah ;Get date function call
Lea DI,Dest ;Get address of destination
Mov AL,DH ;Get month in AL
Call Gdtp ;Convert byte to ascii
Mov Word ptr [DI],'/' ;Move in /
Inc DI ;Point to next byte
Mov AL,DL ;Get day in AL
Call Gdtp ;Convert byte to ascii
Mov Word ptr [DI],'/' ;Move in /
Inc DI ;Point to next byte
Mov AX,CX ;Get year in AL
Mov BL,100d ;Move in divisor
Div BL ;Divide by 100
Mov AL,AH ;Remainder to AL
Call Gdtp ;Convert byte to Ascii
Jmp Short Gdte ;Jump around proc
Gdtp Proc Near
AAM ;Convert to packed decimal
Add AX,3030h ;Convert to ASCII
Mov Byte ptr [DI],AH ;Store high order byte
Inc DI ;Point to next byte
Mov Byte Ptr [DI],AL ;Store low order byte
Inc DI ;Point to next byte
Ret ;Return to caller
Gdtp Endp
Gdte Label Near
Else
Ifidn <Type>,<Bin> ;If Binary request
Doscall 2Ah ;Get current date
Mov Byte ptr Dest,DH ;Move month to destination
Mov Byte ptr [Dest+1],DL ;Move dat to destination
Mov Word ptr [Dest+2],CX ;Move year to destination
Endif
Endif
Endm
Gettime Macro Dest,Type
Local Gtmp,Gtme
;;***************************************************************************;;
;; ;;
;; Macro: Gettime ;;
;; ;;
;; Description: Get current time into Destination ;;
;; ;;
;; Paramaters: Destination, Type (Char or Bin) ;;
;; ;;
;; Input: None ;;
;; ;;
;; Output: HH:MM:SS:HH (Char) or HMSH (Bin) ;;
;; ;;
;; Registers Used: AX,BX,CX,DX,DI ;;
;; ;;
;;***************************************************************************;;
Ifidn <Type>,<Char> ;If character request
Doscall 2Ch ;Get current time
Lea DI,Dest ;Get destination address
Mov AL,CH ;Move hours to AL
Call Gtmp ;And convert to ASCII
Mov Word ptr [DI],':' ;Put in :
Inc DI ;Point to next byte
Mov AL,CL ;Move minutes to AL
Call Gtmp ;And convert to ASCII
Mov Word ptr [DI],':' ;Put in :
Inc DI ;Point to next byte
Mov AL,DH ;Move seconds to AL
Call Gtmp ;And convert to ASCII
Mov Word ptr [DI],':' ;Put in :
Inc DI ;Point to next byte
Mov AL,DL ;Move hundreths to AL
Call Gtmp ;And convert to ASCII
Jmp Short Gtme ;Jump around proc
Gtmp Proc Near
AAM ;Convert to packed decimal
Add AX,3030h ;Convert to ASCII
Mov Byte ptr [DI],AH ;Store high order byte
Inc DI ;Point to next byte
Mov Byte Ptr [DI],AL ;Store low order byte
Inc DI ;Point to next byte
Ret ;Return to caller
Gtmp Endp
Gtme Label Near
Else
Ifidn <Type>,<Bin> ;If request for Binary time
Doscall 2Ch ;Get current time
Mov Byte ptr Dest,CH ;Move hours to destination
Mov Byte ptr Dest+1,CL ;Move minutes to destination
Mov Byte ptr Dest+2,DH ;Move seconds to destination
Mov Byte ptr Dest+3,DL ;Move hundreths to destination
Endif
Endif
Endm
Locate Macro Row,Column
Local Loc1,Locd
;;***************************************************************************;;
;; ;;
;; Macro: Locate ;;
;; ;;
;; Description: Position Cursor on screen ;;
;; ;;
;; Paramaters: Row, Column ;;
;; ;;
;; Input: Binary row and column location, if not in macro call ;;
;; ;;
;; Output: None ;;
;; ;;
;; Registers Used: AX,DX ;;
;; ;;
;;***************************************************************************;;
Mov AL,Row ;Get binary row
Aam ;Convert to packed decimal
Add AX,3030h ;Convert to Ascii
Mov Byte Ptr [Locd+2],AH ;High order row to string
Mov Byte Ptr [Locd+3],AL ;Low order row to string
Clear AH ;Clear AH again
Mov AL,Column ;Get column in AL
Aam ;Convert to packed decimal
Add AX,3030h ;Convert to Ascii
Mov Byte Ptr [Locd+5],AH ;High order column to string
Mov Byte Ptr [Locd+6],AL ;Low order column ti string
Display Locd ;Position the cursor
Jmp Short Loc1 ;Jump around string
Locd Db 1bh,'[ ; H$' ;Position cursor string
Loc1 Label Near
Endm
Move Macro To,From,Lngth
Local Movelp
;;***************************************************************************;;
;; ;;
;; Macro: Move ;;
;; ;;
;; Description: Multiple byte move ;;
;; ;;
;; Paramaters: To location, from location, Length (Opt.) ;;
;; ;;
;; Input: Source string ;;
;; ;;
;; Output: Destination string ;;
;; ;;
;; Registers Used: CX,SI,DI (ES assumed pointing to destination segment) ;;
;; ;;
;;***************************************************************************;;
Clear CH ;Clear length reg
Ifb <Length> ;If no length requested
Mov CX,Length To ;Use length of to string
Else ;If length requested
Mov CX,Lngth ;Use length in macro
Endif
Ifdif <To>,<DI> ;If DI not specified for To
Lea DI,To ;Load To address into DI
Endif
Ifdif <From>,<SI> ;If SI not specified for From
Lea SI,From ;Load From address into SI
Endif
Cld ;Clear direction flag
Rep Movsb ;Move the data
Endm
Restore Macro R1,R2,R3,R4,R5,R6,R7,R8,R9,R10
;;***************************************************************************;;
;; ;;
;; Macro: Restore ;;
;; ;;
;; Description: Restore registers from stack ;;
;; ;;
;; Paramaters: Registers to be restored (in reverse order) ;;
;; ;;
;; Input: None ;;
;; ;;
;; Output: Restored registers ;;
;; ;;
;; Registers Used: None ;;
;; ;;
;;***************************************************************************;;
Irp Rx,<R10,R9,R8,R7,R6,R5,R4,R3,R2,R1> ;Repeat for each parm
Ifnb <Rx> ;If this parm not blank
Pop Rx ;Pop the register
Endif ;End Ifnb
Endm ;End Irp
Endm
Save Macro R1,R2,R3,R4,R5,R6,R7,R8,R9,R10
;;***************************************************************************;;
;; ;;
;; Macro: Save ;;
;; ;;
;; Description: Save registers on the stack ;;
;; ;;
;; Paramaters: Registers to be saved ;;
;; ;;
;; Input: None ;;
;; ;;
;; Output: Registers saved on stack ;;
;; ;;
;; Registers Used: None ;;
;; ;;
;;***************************************************************************;;
Irp Rx,<R1,R2,R3,R4,R5,R6,R7,R8,R9,R10> ;Repeat for each parm
Ifnb <Rx> ;If this parm not blank
Push Rx ;Save the register
Endif ;End Ifnb
Endm ;End Irp
Endm
Setint Macro Interrupt,Routine
;;***************************************************************************;;
;; ;;
;; Macro: Setint ;;
;; ;;
;; Description: Set interrupt vector ;;
;; ;;
;; Paramaters: Interrupt vector, interrupt routine address ;;
;; ;;
;; Input: None ;;
;; ;;
;; Output: None ;;
;; ;;
;; Registers Used: AX,DX ;;
;; ;;
;;***************************************************************************;;
Mov AL,Interrupt ;Get interrupt to be set
Lea DX,Routine ;Get address of routine
Doscall 25h ;Call DOS
Endm
Settime Macro Hours,Minutes,Seconds,Hundreths
;;***************************************************************************;;
;; ;;
;; Macro: Settime ;;
;; ;;
;; Description: Set current time ;;
;; ;;
;; Paramaters: Hours, Minutes, Seconds,Hundreths ;;
;; ;;
;; Input: Time to be set ;;
;; ;;
;; Output: None ;;
;; ;;
;; Registers Used: AX,CX,DX ;;
;; ;;
;;***************************************************************************;;
Ifnb <Hours> ;If hours specified
Mov CH,Hours ;Move hours to CH
Else ;If hours not specified
Clear CH ;Clear CH
Endif
Ifnb <Minutes> ;If minutes specified
Mov CL,Minutes ;Move minutes to CL
Else ;If minutes not specified
Clear CL ;Clear CL
Endif
Ifnb <Seconds> ;If seconds specified
Mov DH,Seconds ;Move seconds to DH
Else ;If seconds not specified
Clear DH ;Clear DH
Endif
Ifnb <Hundreths> ;If hundreths specified
Mov DL,Hundreths ;Move hundreths to DL
Else ;If hndreths not specified
Clear DL ;Clear DL
Endif
Doscall 2dh ;Call DOS to set time
Endm